﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ClassLibrary;

namespace TheBestPlayer2016
{
    /// <summary>
    /// Logique d'interaction pour ChoosePlayer.xaml
    /// </summary>
    public partial class ChoosePlayer : Window
    {
        public Match SelectedMatch { get; internal set; }

        public ChoosePlayer(Match selectedMatch)
        {
            InitializeComponent();
            SelectedMatch = selectedMatch;
            UpdatePlayers();
            
        }

        public void UpdatePlayers()
        {
            List<Player> players = new List<Player>();
            players.AddRange(SelectedMatch.TeamAway.Players);
            players.AddRange(SelectedMatch.TeamHome.Players);
            dataGrid.ItemsSource = players;
        }


        private void backToMainWindow_Click(object sender, RoutedEventArgs e)
        {
            App.MainWindowEl.Show();
            App.ChoosePlayerEl.Hide();
        }

        private void vote_Click(object sender, RoutedEventArgs e)
        {
            if (App.Server != null)
                App.Server.VoteForPlayer((Player)dataGrid.SelectedItem, SelectedMatch);
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            App.MainWindowEl.Close();
           
        }
    }
}
